package cn.virens.cmpt.server.runnable;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.virens.cmpt.server.channel.ChannelSimple;
import cn.virens.cmpt.server.handler.AsynchronousSocketAcceptHandler;

public abstract class AbstractRunnable<D> implements Runnable {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	protected final Queue<D> queue = new ConcurrentLinkedQueue<>();

	protected final ChannelSimple channel;

	public AbstractRunnable(ChannelSimple channel) {
		this.channel = channel;
	}

	@Override
	public void run() {
	}

	public void offer(D data) {
		this.queue.offer(data);
	}

	public void execute() {
		getAcceptHandler().execute(this);
	}

	protected AsynchronousSocketAcceptHandler getAcceptHandler() {
		return channel.getAcceptHandler();
	}

}
